package com.example.propertymangesystem.controller;

import com.example.propertymangesystem.controller.util.R;
import com.example.propertymangesystem.domain.manger;
import com.example.propertymangesystem.service.IMangerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;

@RestController
@RequestMapping("/mangers")
public class mangerController {
    @Autowired
    private IMangerService mangerService;

    @GetMapping("/{id}")
    public R getById(@PathVariable String id){
        manger manger = mangerService.getById(id);
        boolean b = manger != null;
        return new R(b, manger);
    }

   /* @PostMapping("/{fileImage}")
    public String uploadImage(@RequestParam("fileImage") MultipartFile fileImage) throws IOException {
        if(fileImage.isEmpty())
        {
            System.out.println("失败");
            return "上传失败！";
        }else {
            //        获取文件名称
            String originalFilename = fileImage.getOriginalFilename();
            fileImage.transferTo(new File("E:\\javaWeb\\propertyMangeSystem\\src\\main\\resources\\static\\images\\upload\\"+originalFilename));
            System.out.println("成功"+ originalFilename);
        }
        return "上传成功！";
    }*/

    @PutMapping
    public R update(@RequestBody manger manger){
        boolean b = mangerService.updateById(manger);
        return new R(b, b ? "修改成功^_^":"修改失败^…^");
    }
}
